﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Cstudy.DAL
{
    public class attachment
    {
        public bool AddAttachment(MODEL.attachment att)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@resID",att.ResID),
                new SqlParameter("@name",att.Name),
                new SqlParameter("@attdescription",att.Descscription),
                new SqlParameter("@url",att.Url),
                new SqlParameter("@size",att.Size)
            };
            return COM.SQLHelper.ExecuteNonQuery("sp_AddAttachment", parms);
        }

        public bool DeleteAttachmentByFileID(int fileid)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@fileid",fileid)
            };
            return COM.SQLHelper.ExecuteNonQuery("sp_DeleteAttByFileID", parms);
        }

        public bool DeleteAttachmentByResID(int resid)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@resid",resid)
            };
            return COM.SQLHelper.ExecuteNonQuery("sp_DeleteAttByResID", parms);
        }

        public bool UpdateAttachment(MODEL.attachment att)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@fileid",att.fileID),
                new SqlParameter("@resID",att.ResID),
                new SqlParameter("@name",att.Name),
                new SqlParameter("@attdes",att.Descscription),
                new SqlParameter("@url",att.Url),
                new SqlParameter("@size",att.Size)
            };
            return COM.SQLHelper.ExecuteNonQuery("sp_UpdateAtt", parms);
        }

        public DataSet SelectAttachmentByFileID(int fileid)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@fileid",fileid)
            };
            return COM.SQLHelper.ExecuteQuery("sp_SelectAttByFileID", parms);
        }

        public DataSet SelectAttachmentByResID(int resid)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@resid",resid)
            };
            return COM.SQLHelper.ExecuteQuery("sp_SelectAttByResID", parms);
        }
        
    }
}
